﻿/// <summary>
/// FileName: EquipmentSettings.cs
/// Author: Jiang Xiaolong
/// Created Time: 2015.01.15
/// Version: 1.0
/// Company: Sunnytech
/// Function: 平台设备名管理
///
/// Changed By:
/// Modification Time:
/// Discription:
/// </summary>
using UnityEngine;
using Newtonsoft.Json;
using System.IO;
using System.Collections.Generic;
using Motion.MotionPlatform;

public class EquipmentSettings
{
	/// <summary>
	/// 当前设备名称；
	/// </summary>
	public static string CurrentEquipment = "testEquipment";

	/// <summary>
	/// 当前设备英文名和中文名查询字典；
	/// </summary>
	public static Dictionary<string, string> EquipDic = new Dictionary<string, string>();

	private static EquipmentList equipData = new EquipmentList();

	/// <summary>
	/// 静态构造函数，在第一次调用到以上参数时会自动运行；
	/// </summary>
	static EquipmentSettings()
	{
		try
		{
			string jsonReadText = @"";
			jsonReadText += File.ReadAllText(Application.streamingAssetsPath + MotionPlatformData.equipmentSettings);
			equipData = JsonConvert.DeserializeObject<EquipmentList>(jsonReadText);
		}
		catch
		{
			Debug.LogWarning("路径：" + Application.streamingAssetsPath + MotionPlatformData.equipmentSettings + "，设备列表文件读取错误，启用默认设备名: testEquipment！");
			CurrentEquipment = "testEquipment";
		}
		if (equipData != null)
		{
			if (equipData.DefaultEquip != "")
			{
				CurrentEquipment = equipData.DefaultEquip;
			}
			else
			{
				CurrentEquipment = "testEquipment";
			}
			EquipDic.Clear();
			if (equipData.EquipDic != null)
			{
				if (!equipData.EquipDic.ContainsKey(CurrentEquipment))
				{
					Debug.LogWarning("路径：" + Application.streamingAssetsPath + MotionPlatformData.equipmentSettings + "，设备列表不包含默认设备：" + CurrentEquipment + "，请检查该文件填写是否正确！");
				}
				foreach (string key in equipData.EquipDic.Keys)
				{
					EquipDic.Add(key, equipData.EquipDic[key]);
				}
			}
		}
	}

	/// <summary>
	/// 切换设备；
	/// </summary>
	/// <param name="equip_name">设备名；</param>
	public static void ChangeEquipment(string equip_name)
	{ 
		
	}
}

/// <summary>
/// 设备信息数据结构；
/// </summary>
public class EquipmentList
{
	public string DefaultEquip = "";
	public Dictionary<string, string> EquipDic = new Dictionary<string, string>();
}
